<template>
	<view class="content">
		<view class="uni-list">
			<view class="uni-list-cell" hover-class="uni-list-cell-hover" v-for="(item,index) in newsList" :key="index"
			@click="goInfo" :data-newsid="item.post_id">
				<view class="uni-media-list">
					<image class="uni-media-list-logo" :src="item.author_avatar"></image>
					<view class="uni-media-list-body">
						<view class="uni-media-list-text-top">{{item.title}}</view>
						<view class="uni-media-list-text-bottom uni-ellipsis">{{item.created_at}}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
import { ref } from 'vue';
	
	const newsList = ref([]) 
	
	const getnews = async ()=> {
		uni.showLoading({
			title:"加载中..."
		})
		
	    let res = await uni.request({
	        url: 'https://unidemo.dcloud.net.cn/api/news',
	        method: 'GET',
	        data: {},
	        success: (res) => {
				newsList.value=res.data;
				uni.hideLoading();
	        },
	        fail: (err) => {
	        }
	    });
	}
	
	const goInfo = function(e) {
	    const newsid = ref()
	    newsid.value = e.currentTarget.dataset.newsid;
		uni.navigateTo({
			url:'/pages/info/info?newsid='+newsid.value,
	    });
	}
	getnews()
</script>

<style lang="scss" scoped> 
.uni-media-list-body{
	height: auto;
}
.uni-media-list-text-top{
	line-height: 1.6em;
}
</style>
